/*
 * Copyright (c) 2007 empronix (http://www.empronix.com)
 * Author: Benedikt Sauter <sauter@empronix.com>
 * All rights reserved.
 *
 * Short descripton of file:
 *
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions 
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright 
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above 
 *     copyright notice, this list of conditions and the following 
 *     disclaimer in the documentation and/or other materials provided 
 *     with the distribution.
 *   * Neither the name of the FH Augsburg nor the names of its 
 *     contributors may be used to endorse or promote products derived 
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef IO_H
#define IO_H

#include <avr/io.h>
#include <avr/pgmspace.h>


#define OX_PIN1 PINE
#define OX_PIN2 PINE
#define OX_PIN3 PINE
#define OX_PIN4 PINB
#define OX_PIN5 PINB
#define OX_PIN6 PINB
#define OX_PIN7 PINB
#define OX_PIN8 PINB
#define OX_PIN9 PINB
#define OX_PIN10 PINB
#define OX_PIN11 PINB
#define OX_PIN12 PIND
#define OX_PIN13 PIND
#define OX_PIN14 PIND
#define OX_PIN15 PIND
#define OX_PIN16 PIND
#define OX_PIN17 PIND
#define OX_PIN18 PIND
#define OX_PIN19 PIND

#define OX_PIN26 PINC
#define OX_PIN27 PINC
#define OX_PIN28 PINC
#define OX_PIN29 PINC
#define OX_PIN30 PINC
#define OX_PIN31 PINC
#define OX_PIN32 PINC
#define OX_PIN33 PINF
#define OX_PIN34 PINF
#define OX_PIN35 PINF
#define OX_PIN36 PINF
#define OX_PIN37 PINF
#define OX_PIN38 PINF
#define OX_PIN39 PINF
#define OX_PIN40 PINF
#define OX_PIN41 PINE
#define OX_PIN42 PINE
#define OX_PIN43 PINE
#define OX_PIN44 PINE

#define OX_PORT1 PORTE
#define OX_PORT2 PORTE
#define OX_PORT3 PORTE
#define OX_PORT4 PORTB
#define OX_PORT5 PORTB
#define OX_PORT6 PORTB
#define OX_PORT7 PORTB
#define OX_PORT8 PORTB
#define OX_PORT9 PORTB
#define OX_PORT10 PORTB
#define OX_PORT11 PORTB
#define OX_PORT12 PORTD
#define OX_PORT13 PORTD
#define OX_PORT14 PORTD
#define OX_PORT15 PORTD
#define OX_PORT16 PORTD
#define OX_PORT17 PORTD
#define OX_PORT18 PORTD
#define OX_PORT19 PORTD

#define OX_PORT26 PORTC
#define OX_PORT27 PORTC
#define OX_PORT28 PORTC
#define OX_PORT29 PORTC
#define OX_PORT30 PORTC
#define OX_PORT31 PORTC
#define OX_PORT32 PORTC
#define OX_PORT33 PORTF
#define OX_PORT34 PORTF
#define OX_PORT35 PORTF
#define OX_PORT36 PORTF
#define OX_PORT37 PORTF
#define OX_PORT38 PORTF
#define OX_PORT39 PORTF
#define OX_PORT40 PORTF
#define OX_PORT41 PORTE
#define OX_PORT42 PORTE
#define OX_PORT43 PORTE
#define OX_PORT44 PORTE

#define OX_DDR1 DDRE
#define OX_DDR2 DDRE
#define OX_DDR3 DDRE
#define OX_DDR4 DDRB
#define OX_DDR5 DDRB
#define OX_DDR6 DDRB
#define OX_DDR7 DDRB
#define OX_DDR8 DDRB
#define OX_DDR9 DDRB
#define OX_DDR10 DDRB
#define OX_DDR11 DDRB
#define OX_DDR12 DDRD
#define OX_DDR13 DDRD
#define OX_DDR14 DDRD
#define OX_DDR15 DDRD
#define OX_DDR16 DDRD
#define OX_DDR17 DDRD
#define OX_DDR18 DDRD
#define OX_DDR19 DDRD

#define OX_DDR26 DDRC
#define OX_DDR27 DDRC
#define OX_DDR28 DDRC
#define OX_DDR29 DDRC
#define OX_DDR30 DDRC
#define OX_DDR31 DDRC
#define OX_DDR32 DDRC
#define OX_DDR33 DDRF
#define OX_DDR34 DDRF
#define OX_DDR35 DDRF
#define OX_DDR36 DDRF
#define OX_DDR37 DDRF
#define OX_DDR38 DDRF
#define OX_DDR39 DDRF
#define OX_DDR40 DDRF
#define OX_DDR41 DDRE
#define OX_DDR42 DDRE
#define OX_DDR43 DDRE
#define OX_DDR44 DDRE


#define OX_P1 PE5
#define OX_P2 PE6
#define OX_P3 PE7
#define OX_P4 PB0
#define OX_P5 PB1
#define OX_P6 PB2
#define OX_P7 PB3
#define OX_P8 PB4
#define OX_P9 PB5
#define OX_P10 PB6
#define OX_P11 PB7
#define OX_P12 PD0
#define OX_P13 PD1
#define OX_P14 PD2
#define OX_P15 PD3
#define OX_P16 PD4
#define OX_P17 PD5
#define OX_P18 PD6
#define OX_P19 PD7

#define OX_P26 PC0
#define OX_P27 PC1
#define OX_P28 PC2
#define OX_P29 PC3
#define OX_P30 PC4
#define OX_P31 PC5
#define OX_P32 PC6
#define OX_P33 PF7
#define OX_P34 PF6
#define OX_P35 PF5
#define OX_P36 PF4
#define OX_P37 PF3
#define OX_P38 PF2
#define OX_P39 PF1
#define OX_P40 PF0
#define OX_P41 PE0
#define OX_P42 PE1
#define OX_P43 PE2
#define OX_P44 PE3



void io_parser(char *buf);

int io_init(int pin);
void io_init_usb(int pin);
void io_init_port(int port);

int io_set_port_direction_out(int port,unsigned char mask);
int io_set_port_direction_in(int port, unsigned char mask);
int io_set_port_direction_tri(int port, unsigned char mask);

void io_set_port_direction_out_usb(int port,unsigned char mask);
void io_set_port_direction_in_usb(int port, unsigned char mask);
void io_set_port_direction_tri_usb(int port, unsigned char mask);


int io_set_pin_direction_out(int pin);
int io_set_pin_direction_in(int pin);
int io_set_pin_direction_tri(int pin);

void io_set_pin_direction_out_usb(int pin);
void io_set_pin_direction_in_usb(int pin);
void io_set_pin_direction_tri_usb(int pin);

void io_get_port(int port);
void io_get_port_bulk(int port, int number);

void io_set_port(int port, unsigned char value);
void io_set_port_bulk(int port, int number, unsigned char * buf);

int io_set_pin(int pin, int value); 
void io_set_pin_usb(int pin, int value); 
void io_set_pin_bulk(int pin, int number, int * buf);

int io_get_pin(int pin, int *value);
void io_get_pin_usb(int pin);
void io_get_pin_bulk(int pin, int number);

#endif /* IO_H */
